﻿using UnityEngine;
using System.Collections;

/// <summary>
/// 本地存储
/// </summary>
public class LocalStorage {

    /// <summary>
    /// 判断是否有这个键
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static bool HasKey(string name)
    {
        return PlayerPrefs.HasKey(name);
    }

    /// <summary>
    /// 删除键
    /// </summary>
    /// <param name="name"></param>
    public static void ClearKey(string name)
    {
        DebugInfo.Log("LocalStorage.ClearKey: " + name);
        PlayerPrefs.DeleteKey(name);
    }

    /// <summary>
    /// 设置float变量
    /// </summary>
    /// <param name="name"></param>
    /// <param name="value"></param>
    public static void SetFloat(string name, float value)
    {
        DebugInfo.Log("LocalStorage.SetFloat: " + name + " -> " + value);
        PlayerPrefs.SetFloat(name, value);
    }

    /// <summary>
    /// 获取float变量
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static float GetFloat(string name)
    {
        return PlayerPrefs.GetFloat(name);
    }

    /// <summary>
    /// 设置字符串变量
    /// </summary>
    /// <param name="name"></param>
    /// <param name="value"></param>
    public static void SetString(string name, string value)
    {
        DebugInfo.Log("LocalStorage.SetString: " + name + " -> " + value);
        PlayerPrefs.SetString(name, value);
    }

    /// <summary>
    /// 获取字符串变量
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static string GetString(string name)
    {
        return PlayerPrefs.GetString(name);
    }

    /// <summary>
    /// 保存整形值
    /// </summary>
    /// <param name="name"></param>
    /// <param name="value"></param>
    public static void SetInt(string name, int value)
    {
        DebugInfo.Log("LocalStorage.SetInt: " + name + " -> " + value);
        PlayerPrefs.SetInt(name, value);
    }

    /// <summary>
    /// 获取整形值
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static int GetInt(string name)
    {
        return PlayerPrefs.GetInt(name);
    }
}
